package xyz.msj.hrm.feign.fallback;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import xyz.msj.hrm.feign.client.MQFeignClient;
import xyz.msj.hrm.util.AjaxResult;
import xyz.msj.hrm.vo.SendEmailVO;
import xyz.msj.hrm.vo.SendSMSVO;
import xyz.msj.hrm.vo.SendSystemMessageVO;

/**
 * 兜底方法
 */
@Component
@Slf4j
public class MQFeignClientFackBallFactory implements FallbackFactory<MQFeignClient> {
    @Override
    public MQFeignClient create(Throwable throwable) {
        return new MQFeignClient() {
            @Override
            public AjaxResult sendSMS(SendSMSVO vo) {
                log.error("发送短信失败！");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("发送短信失败");
            }

            @Override
            public AjaxResult sendEmail(SendEmailVO vo) {
                log.error("发送邮件失败！");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("发送邮件失败");
            }

            @Override
            public AjaxResult sendSystemMessage(SendSystemMessageVO vo) {
                log.error("发送系统消息失败！");
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("发送系统消息失败");
            }
        };
    }
}
